Create project with C application and print to debug console

In this step you first create a new Kanzi Studio project with C application, and then add the code to the C application to print Hello world! to the Kanzi debug console.

  1. In Kanzi Studio Quick Start window click New Project...:
    1. Choose the name and location for your project.
      For example, name your project Hello world.
    2. In Project Type select Kanzi Studio project with C application.

    Kanzi creates a Kanzi Studio project in <KanziWorkspace>/Projects/<ProjectName>/Tool_project directory and the structure for the Visual Studio solution for your project in <KanziWorkspace>/Projects/<ProjectName>/Application:

  2. In Kanzi Studio select File > Export KZB Binary.
    Kanzi Studio creates the binary and configuration files from your Kanzi Studio project and stores them in <KanziWorkspace>/Projects/<ProjectName>/Application/bin. When you run your Kanzi application from Visual Studio, your Visual Studio solution reads these files to create your Kanzi application.
  3. In Visual Studio open the Visual Studio solution for your application located in <KanziWorkspace>/Projects/<ProjectName>/Application/configs/platforms/win32.
    For example, if you named your Kanzi Studio project Hello world, Visual Studio solution is called Hello_world.sln.
  4. Open hello_world.c and include the kzc_log.h header.
    /* Core logging */
    #include <core/debug/kzc_log.h>

    kzc_log.h header contains the functions that define the functionality for writing to Kanzi debug console.
  5. Create a function that writes to Kanzi debug console.
    KZ_CALLBACK static kzsError writeToLog(struct KzaApplication* application)
    {
    	/* Prints Hello world! to the Kanzi debug console. */
    	kzsLog(KZS_LOG_LEVEL_INFO, "Hello world!");
    	
    	kzsSuccess();
    }
  6. In the kzApplicationConfigure function call your writeToLog function when your Kanzi application loads.
    configuration->onProjectLoaded = writeToLog;
  7. In Visual Studio select one of the available debug solution configurations and run your application.
    For example, select ES2_IMG_Debug solution configuration.

    Function writeToLog prints Hello world! to the Kanzi debug console.

    When in the debug mode, along with the Kanzi debug console, your Kanzi application is shown in the Kanzi player. Since by default a new Kanzi Studio project contains only a scene with a camera and a directional light, your application, shows an empty scene.

This is what your hello_world.c looks like when you complete this step.

#include <application/kza_application_interface.h>
#include <application/kza_application.h>
/* Core logging */
#include <core/debug/kzc_log.h>

KZ_CALLBACK static kzsError keyInputEventHandler(struct KzaApplication*
	application, const struct KzsInputEventKey* inputData)
{
	enum KzsInputKey button = kzsInputEventKeyGetButton(inputData);

	/* Handle the escape or Q button to exit the application. */
	if (button == KZS_KEY_ESC || button == KZS_KEY_Q)
	{
		kzaApplicationQuit(application);
	}

	kzsSuccess();
}

KZ_CALLBACK static kzsError writeToLog(struct KzaApplication* application)
{
	/* Prints Hello world! to the Kanzi debug console. */
	kzsLog(KZS_LOG_LEVEL_INFO, "Hello world!");

	kzsSuccess();
}

KZ_CALLBACK void kzApplicationConfigure(const struct KzaSystemProperties*
	systemProperties, struct KzaApplicationProperties* configuration)
{
	configuration->memoryPoolSize = 20 * 1024 * 1024;
	configuration->binaryName = "Hello_World.kzb.cfg";

	configuration->onKeyInputEvent = keyInputEventHandler;
	/* Calls the writeToLog function when the project is loaded. */
	configuration->onProjectLoaded = writeToLog;
}

< PREVIOUS STEP

NEXT STEP >

See also

API reference